package service

import (
	"main/dao"
	"main/model"
	"strconv"
)

type ShopService struct {

}

func (s *ShopService) GetService(id int64) []model.Service {
	sd := dao.NewShopDao()

	return sd.QueryServiceByShopId(id)
}

func (s *ShopService) SearchShops(lgt, lat, keyword string) ([]model.Shop, error) {
	longitude, err := strconv.ParseFloat(lgt, 10)
	if err != nil {
		return nil, err
	}
	latitude, err := strconv.ParseFloat(lat, 10)
	if err != nil {
		return nil, err
	}

	sd := dao.NewShopDao()
	shops, err := sd.QueryShops(longitude, latitude, keyword)
	if err != nil {
		return nil, err
	}
	return shops, nil
}


// ShopList 附近的商家
func (s *ShopService) ShopList(lgt, lat string) ([]model.Shop, error) {
	longitude, err := strconv.ParseFloat(lgt, 10)
	if err != nil {
		return nil, err
	}
	latitude, err := strconv.ParseFloat(lat, 10)
	if err != nil {
		return nil, err
	}

	sd := dao.NewShopDao()
	shops, err := sd.QueryShops(longitude, latitude, "")
	if err != nil {
		return nil, err
	}
	return shops, nil
}
